<?php  
namespace Admin\Controller;
use Common\Controller\AdminBaseController;
/**
 * 分类管理
 */
class CategoryController extends AdminBaseController
{
	 //定义数据表
    
	public function index()
	{
		$data = M('category')->select();
		p($data);die;
		$this->assign('data',$data);
		$this->display();


	}
	public function add()
	{
		$this->display();
	}
	public function insert()
	{
		if (empty($_POST)) {
			$this->error('表单不能为空');
			exit;
		}
		M('category')->create();
		if (M('category')->add() > 0 ) {
            $this->success('添加成功',U('index'));
        } else {
            $this->error('添加失败');
        }
	}
	public function delete()
	{
		$cid = I('get.cid',0,'intval');
	       // echo $uid;
	       $id = M('category')->delete($cid);
	       if ($id > 0) {
	       		$this->success('删除成功');
	       }else{
	       		$this->error('删除失败');
	       }
	}
	public function edit()
	{	
		$cid = I('get.cid',0,'intval');
		$data = M('category')->where(array('cid'=>$cid))->find();
		$this->assign('data',$data);
		$this->display();
	}
	public function save()
	{
		if (!IS_POST) {
			E('非法操作');
		}		
		if (empty($_POST)) {
			$this->error('数据不能为空');
		}
		M('category')->create();
		if (M('category')->save() > 0) {
			$this->success('编辑成功',U('Admin/Category/index'));
		}else{
			$this->error('编辑失败');
		}

	}

}